//***********************************************************************
//	File:		Basher.cpp
//	Author:		
//	Course:		SGP 1405
//	Purpose:	
//***********************************************************************
//***********************************************************************
//	Purposfully left blank for all comments regarding this file 
//	
//	
//	
//***********************************************************************





#include "Basher.h"
#include "../SGD Wrappers/SGD_Event.h"

Basher::Basher(float posX, float posY)// : SGD::Listener(this), Enemy(posX, posY)
{
	/*
	SetAcceleration({ 0, 0 });
	SetAttackCDL(.5f);
	SetAttackRange(500);
	SetConfuseCDL(4);
	SetConfuseTimer(0);

	SetHealth(100);
	//SetImage();
	SetKnockbackCDL(4);
	SetKnockBackTimer(0);
	SetMass(90);
	SetMaxHealth(100);
	SetMaxSpeed(100);
	SetPassable(false);
	SetPosition(SGD::Point{ posX, posY });
	SetRootCDL(4);
	SetRootTimer(0);
	SetRotation(0);
	SetSize(SGD::Size{ 64, 64 });
	SetSpeed(100);
	SetStaticFrictionCoefficient(0.7f);
	SetDynamicFrictionCoefficient(.03f);
	SetDragForceCoefficient(0.04f);
	//SetTakeDamage() particle emitter
	SetValue(ENT_ANKLEBITER);
	SetVelocity(SGD::Vector{ 0, 0 });
	SetTarget((Entity *)Play::GetInstance()->GetPlayer());
	RegisterForEvent("CONCUSSION_BLAST");
	*/

}

Basher::~Basher()
{
	SGD::GraphicsManager::GetInstance()->UnloadTexture(m_hImage);

	int * points = new int(10);
	SGD::Event * pEvent = new SGD::Event ( "INCREASE_SCORE", points, nullptr);
	pEvent->QueueEvent(nullptr);
	pEvent = nullptr;
}

//Interface
void Basher::Update(float dt)
{


	if (m_bMove == true)
	{
	
	if (pTarget2)
	{
		SGD::Vector vec = pTarget2->GetPosition() - GetPosition();
		vec.Normalize();
		vec *= 75.0f;

		SetPosition(GetPosition() + vec * dt);
	}


	if (pTarget2->GetPosition().x - this->GetPosition().x <= 5 && pTarget2->GetPosition().y - this->GetPosition().y <= 5)
		Attack(dt);

	if (m_fAttackCDL <= 0)
	m_fAttackCDL -= dt;

	}

	//Last line of function
	Entity::Update(dt); 
}

void Basher::Render()
{
	

	SGD::GraphicsManager::GetInstance()->DrawTexture(m_hImage, GetPosition(), 0.0, SGD::Vector(0, 0), SGD::Color(), SGD::Size(64, 64));
}

void Basher::HandleCollision(const IEntity* pOther)
{
	Entity::HandleCollision(pOther);
}

void Basher::HandleEvent()
{

}

SGD::Rectangle Basher::GetRect() const
{
	return SGD::Rectangle{}; 
}

void Basher::ModifyHealth(float hpAmount)
{
	m_fTotalHP -= hpAmount;

	pTarget2->ModifyHealth(-30);
}

void Basher::ApplyFriction(float dt)
{

}

void Basher::Attack(float dt)
{

	if (pTarget2->GetPosition().x - this->GetPosition().x <= 5 && pTarget2->GetPosition().y - this->GetPosition().y <= 5)
	{

		if (m_fAttackCDL <= 0)
		{

		GetDamage();
		m_fAttackCDL = 10;

		}

	}

}

void Basher::Move(void)
{
	if (pTarget2->GetPosition().x - this->GetPosition().x <= 400 && pTarget2->GetPosition().y - this->GetPosition().y <= 400)
		m_bMove = true;


}
